﻿using System;
using Microsoft.Xna.Framework.Graphics;
using RebEngine.Interfaces;
using RebEngine.Managers;

namespace RebEngine.Textures
{
    public class RebTexture : IRebTexture
    {
        private string sFileName;
        private Texture tBaseTexture;
        private bool bReadyToRender = false;

        public string FileName
        {
            get { return sFileName; }
            set { sFileName = value; }
        }
        public Texture BaseTexture
        {
            get { return tBaseTexture; }
        }
        public bool ReadyToRender
        {
            get { return bReadyToRender; }
        }

        public RebTexture(string fileName)
        {
            sFileName = fileName;
        }

        public void LoadContent()
        {
            if (!String.IsNullOrEmpty(sFileName))
            {
                try //Try to load the Texture
                {
                    tBaseTexture = EngineManager.ContentManager.Load<Texture>("Content/Textures/" +sFileName);
                    bReadyToRender = true;
                }
                catch // If failed, most likely missing texture so just load the placeholder instead
                {
                    tBaseTexture = EngineManager.ContentManager.Load<Texture>("Content/Textures/placeHolder");
                    bReadyToRender = true;
                }
                
            }
        }

        public void UnloadContent()
        {
            if(tBaseTexture != null)
                tBaseTexture.Dispose();
        }
    }
}